Clean up domains if creation/restoration fails.
authoremellor@ewan <emellor@ewan>
Tue, 4 Oct 2005 17:23:58 +0000 (18:23 +0100)
committeremellor@ewan <emellor@ewan>
Tue, 4 Oct 2005 17:23:58 +0000 (18:23 +0100)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendDomainInfo.py

index 994cd4e1301dc716de4012a1c721c5c1e42c916a..782a1b7d68527e4f14bbaef6844f0980f56b3e81 100644 (file)
@@ -129,9 +129,13 @@ def create(config):
     log.debug("XendDomainInfo.create(%s)", config)
 
     vm = XendDomainInfo(getUuid(), parseConfig(config))
-    vm.construct()
-    vm.refreshShutdown()
-    return vm
+    try:
+        vm.construct()
+        vm.refreshShutdown()
+        return vm
+    except:
+        vm.destroy()
+        raise
 
 
 def recreate(xeninfo):
@@ -195,13 +199,23 @@ def restore(config):
     except TypeError, exn:
         raise VmError('Invalid ssidref in config: %s' % exn)
 
-    vm = XendDomainInfo(uuid, parseConfig(config),
-                        xc.domain_create(ssidref = ssidref))
-    vm.storeVmDetails()
-    vm.configure()
-    vm.create_channel()
-    vm.storeDomDetails()
-    return vm
+    domid = xc.domain_create(ssidref = ssidref)
+    if domid <= 0:
+        raise VmError('Creating domain failed for restore')
+    try:
+        vm = XendDomainInfo(uuid, parseConfig(config), domid)
+    except:
+        xc.domain_destroy(domid)
+        raise
+    try:
+        vm.storeVmDetails()
+        vm.configure()
+        vm.create_channel()
+        vm.storeDomDetails()
+        return vm
+    except:
+        vm.destroy()
+        raise
 
 
 def parseConfig(config):